package com.tanglongan.designPattern.dp21_template.demo99;

public class GenericClient {

    static abstract class AbstractClass {
        protected void step1() {
            System.out.println("AbstractClass:step1");
        }

        protected void step2() {
            System.out.println("AbstractClass:step2");
        }

        protected void step3() {
            System.out.println("AbstractClass:step3");
        }

        /**
         * 通过final修饰，避免子类修改
         */
        public final void templateMethod() {
            this.step1();
            this.step2();
            this.step3();
        }
    }

    static class ConcreteClassA extends AbstractClass {
        @Override
        protected void step1() {
            System.out.println("ConcreteClassA: stpe1");
        }
    }

    static class ConcreteClassB extends AbstractClass {
        @Override
        protected void step2() {
            System.out.println("ConcreteClassA: stpe2");
        }
    }

    public static void main(String[] args) {
        AbstractClass abc = new ConcreteClassA();
        abc.templateMethod();
        abc = new ConcreteClassB();
        abc.templateMethod();
    }
}
